package myself.a011HowAreYou;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author 叶之越
 * Description 会议安排问题
 * Date 2021/1/30
 * Time 22:05
 * Mail 739153436@qq.com
 */
public class BestArrange {
    // 按照会议结束的时间来进行升序排序
    // 在会议结束点之后的会议可以进行串行开展
    // 开展后更新会议阈值
    public static int bestArrange2(Program[] programs) {

        Arrays.sort(programs, Comparator.comparingInt(o -> o.end));
        int count = 0;
        int threshold = 0;
        for (int i = 0; i < programs.length; i++) {
            if (programs[i].start >= threshold) {
                count++;
                threshold = programs[i].end;
            }
        }
        return count;
    }

    public static class Program {
        public int start;
        public int end;

        public Program(int start, int end) {
            this.start = start;
            this.end = end;
        }
    }
}
